#include "StartScene2.h" 
#include "cocostudio/CocoStudio.h"
#include "TollgateScene.h"
#include "TollgateStory.h"
#include "SimpleAudioEngine.h"


using namespace cocos2d::ui;
using namespace cocostudio::timeline;

Scene* StartScene2::createScene(){
	auto scene = Scene::create();

	auto layer = StartScene2::create();

	scene->addChild(layer);

	return scene;
}

bool StartScene2::init(){
	if (!Layer::init()){
		return false;
	}

	auto rootNode = CSLoader::createNode("StartScene2.csb");
	this->addChild(rootNode, 10);
	auto UI = (Widget*)rootNode;
	auto bMBtn = (Button*)Helper::seekWidgetByName(UI, "BarrierModelBtn");
	auto cMBtn = (Button*)Helper::seekWidgetByName(UI, "ChallangeModelBtn");

	bMBtn->addTouchEventListener(this, toucheventselector(StartScene2::onClickBMBtn));
	cMBtn->addTouchEventListener(this, toucheventselector(StartScene2::onClickCMBtn));
	return true;
}

void StartScene2::onClickBMBtn(Ref*, TouchEventType type){
	switch (type)
	{
	case TouchEventType::TOUCH_EVENT_BEGAN:
		CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("music/click.mp3", false);
		break;
	case TouchEventType::TOUCH_EVENT_MOVED:
		break;
	case TouchEventType::TOUCH_EVENT_ENDED:
		Director::getInstance()->replaceScene(TollgateStory::createScene());
		break;
	case TouchEventType::TOUCH_EVENT_CANCELED:
		break;
	default:
		break;
	}
}

void StartScene2::onClickCMBtn(Ref*, TouchEventType type){
	switch (type)
	{
	case TouchEventType::TOUCH_EVENT_BEGAN:
		CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("music/click.mp3", false);
		break;
	case TouchEventType::TOUCH_EVENT_MOVED:
		break;
	case TouchEventType::TOUCH_EVENT_ENDED:
		Director::getInstance()->replaceScene(TollgateScene::createScene(4));
		break;
	case TouchEventType::TOUCH_EVENT_CANCELED:
		break;
	default:
		break;
	}
}
